﻿<ResourceDictionary 
    xmlns:converters="clr-namespace:myCollections.Utils"
    xmlns:local="clr-namespace:myCollections.Controls"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Style TargetType="{x:Type local:Rating}">
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:Rating}">
                    <ControlTemplate.Resources>
                        <converters:NotBooleanToVisbilityConverter x:Key="notBooleanToVisbilityConverter" />
                    </ControlTemplate.Resources>
                    <Viewbox Stretch="Uniform">
                        <Border>
                            <Grid>
                                <!--This extra Border, Grid, Rectangle allow us to display a focus visual style based on a trigger rather than
                                    keyboard activity.  I wanted the use to clearly see the rating control has focus even though the tab key
                                    may not have been pressed.  You can try the EditStuffView with and without the below trigger and you'll see the
                                    different behaviors.-->
                                <Rectangle x:Name="focusRect" Visibility="Hidden" Stroke="Black" StrokeThickness="2" StrokeDashArray="2 6" Margin="-3" SnapsToDevicePixels="True" />
                                <Border DataContext="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}}" Padding="0" Margin="0" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                                    <!--
                                        HACK this is how you data bind to values from within a ToolTip
                                        Remember a ToolTip is popuped up and does not get data from an inherited DataContext, instead you have to pull it in as I've done below
                                    -->

                                    <Border.ToolTip>
                                        <ToolTip DataContext="{Binding Path=PlacementTarget.DataContext, RelativeSource={RelativeSource Mode=Self}}">
                                            <StackPanel Orientation="Vertical">
                                                <TextBlock Margin="3.5" Text="{Binding Path=Value, StringFormat=Rating Value is : \{0\}}" />
                                                <TextBlock Margin="3.5" Text="Click to set value" Visibility="{Binding Path=IsReadOnly, Converter={StaticResource notBooleanToVisbilityConverter}}" />
                                            </StackPanel>
                                        </ToolTip>
                                    </Border.ToolTip>
                                    <Grid Background="Transparent" Height="50" VerticalAlignment="Top" Width="250" HorizontalAlignment="Left">
                                        <Rectangle Margin="2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Fill="{TemplateBinding EmptyStarBrush}" StrokeThickness="0" />
                                        <Rectangle Margin="2" VerticalAlignment="Stretch" HorizontalAlignment="Left" Width="{TemplateBinding ValueWidth}" Fill="{TemplateBinding ValueBrush}" StrokeThickness="0" />
                                        <Path Data="M24.999998,38.196021 L40.450848,49.999999 9.5491486,49.999999 z M225,38.196017 L240.45085,49.999999 209.54915,49.999999 z M175,38.196017 L190.45085,49.999999 159.54915,49.999999 z M125,38.196017 L140.45085,49.999999 109.54915,49.999999 z M75,38.196017 L90.450851,49.999999 59.549149,49.999999 z M250,19.098301 L250,49.999999 240.45085,49.999999 234.54863,30.901518 z M200,19.098301 L215.45137,30.901518 209.54915,49.999999 190.45085,49.999999 184.54863,30.901518 z M150,19.098301 L165.45137,30.901518 159.54915,49.999999 140.45085,49.999999 134.54863,30.901518 z M100,19.098301 L115.45138,30.901518 109.54915,49.999999 90.450851,49.999999 84.548622,30.901518 z M0,19.098298 L15.451375,30.901518 9.5491486,49.999999 0,49.999999 z M225,0 L250,0 250,19.098301 230.90138,19.098771 z M175,0 L225,0 219.09862,19.098771 200,19.098301 180.90138,19.098771 z M125,0 L175,0 169.09862,19.098771 150,19.098301 130.90138,19.098771 z M75,0 L125,0 119.09863,19.098771 100,19.098301 80.901375,19.098771 z M24.999998,0 L75,0 69.098625,19.098771 50,19.098301 65.451378,30.901518 59.549149,49.999999 40.450848,49.999999 34.548626,30.901518 49.999996,19.098298 30.901373,19.098771 z M0,0 L24.999998,0 19.098625,19.098771 0,19.098298 z" Fill="{TemplateBinding ValueSelectorBackground}" Stretch="Fill" StrokeThickness="0" UseLayoutRounding="False"/>
                                    </Grid>
                                </Border>
                            </Grid>
                        </Border>
                    </Viewbox>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsFocused" Value="true">
                            <Setter TargetName="focusRect" Property="Visibility" Value="Visible" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>
